<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="common/head :: htmlhead">
<body>
<style>
    .layui-layer-content {
        overflow: visible !important;
        margin: -10px;
    }
</style>
<div class="layui-fluid">
    <div class="site-text" style="margin: 5%; display: none" id="window">
        <div class="layui-form" action="" lay-filter="addform">
            <div class="layui-row layui-col-space10 layui-form-item">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">选择博物馆</label>
                    <form>
                        <div class="layui-input-block">
                            <select id="museum" name="museum"></select>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="site-text" style="margin: 5%; display: none" id="dhjm">
        <textarea id="dhyj" type="text/plain"
                  style="width:99%;height:165px;resize: none;overflow: scroll;font-size: 18px"> </textarea>
    </div>

    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">博物馆列表</div>
                <div class="layui-card-body">
                    <table id="table_demo" lay-filter="table_demo"></table>
                    <script type="text/html" id="table_toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="addmuseum">添加博物馆</button>
                        </div>
                    </script>
                    <script type="text/html" id="table_operate">
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        {{# if(d.status==="已打回"){ }}
                        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="dhyj">打回意见</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">
    layui.use(['table', 'element', 'form'], function () {
        var table = layui.table
            , element = layui.element
            , form = layui.form;
        var obj = document.getElementById('museum');
        var bwgList = [[${bwgList}]];
        bwgList.forEach(function (bwg) {
            obj.add(new Option(bwg.name, bwg.id));
        });
        table.render({
            elem: '#table_demo'
            , url: '/bwgList'
            , method: 'post'
            , toolbar: '#table_toolbar'
            , defaultToolbar: ['filter', 'print']
            , cellMinWidth: 80
            , page: true
            , cols: [
                [ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'id', title: 'ID', hide: true, sort: true}
                    , {field: 'name', title: '博物馆名称', width: 300}
                    , {field: 'province', title: '所属省份', sort: true, width: 150}
                    , {field: 'status', title: '审核状态', sort: true, width: 150}
                    , {field: 'creattime', title: '提交时间', sort: true,
                    templet:'<div>{{ layui.util.toDateString(d.creattime, "yyyy-MM-dd") }}</div>'}
                    , {field: 'right', title: '操作', toolbar: '#table_operate', width: 200}
                ]
            ]
        });


        table.on('toolbar(table_demo)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'addmuseum':
                    if ([[${bwgList}]]) {
                        layer.open({
                            type: 1
                            , skin: 'layui-layer-molv'
                            , area: ['400px', '200px']
                            , title: ['添加博物馆', 'font-size:18px']
                            , btn: ['前去填写信息', '取消']
                            , shadeClose: true
                            , shade: 0 //遮罩透明度
                            , maxmin: true //允许全屏最小化
                            , content: $("#window")  //弹窗路径
                            , success: function (layero, index) {
                                form.render(null, 'addform');
                            }
                            , yes: function (index, layero) {
                                var bwgid = document.getElementById('museum').value;
                                window.location.href = "/go_bwgztEdit?bwgid=" + bwgid;
                            }
                            , btn2: function (index, layero) {
                                layer.close(index); // 关闭弹出层
                            }
                        });
                    } else {
                        layer.msg("您没有可添加的博物馆！", {icon: 2});
                    }
                    break;
            }
        });

        table.on('tool(table_demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除该博物馆？删除后无法恢复', function (index) {
                    $.ajax({
                        url: "/delBwgzt",
                        async: false,
                        type: "POST",
                        dataType: "text",
                        data: {"id": data.id},
                        success: function (aa) {
                            if (aa === "error") {
                                layer.msg('删除失败！', {icon: 2});
                                location.reload()
                            } else if (aa === "success") {
                                obj.del();
                                layer.close(index);
                                location.reload();
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                window.location.href = "/bwgztEdit?id=" + data.id;
            } else if (obj.event === 'dhyj') {
                layui.use('form', function () {
                    form = layui.form;
                    layer.open({
                        type: 2 //此处以iframe举例
                        , title: '打回意见'
                        , area: ['400px', '200px']
                        , shade: 0
                        , maxmin: true
                        , content: '/getOpinion?id=' + data.id + '&type=museum'
                        , btn: ['确定'] //只是为了演示
                        , btn2: function () {
                            layer.closeAll();
                        }
                    });
                });

            }
        });

    })
</script>
</body>
</html>